package com.lzx.iteam.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.CRMFilterFirstData;
import com.lzx.iteam.bean.CRMFilterSecondData;
import com.lzx.iteam.bean.CRMOrderByData;

import java.util.ArrayList;

/**
 * Created by Megan on 16/7/28.
 */
public class CRMOrderAdapter extends BaseAdapter {

    private ArrayList<CRMOrderByData> mOrderDatas;
    private Context mContext;
    private LayoutInflater mInflater;
    private int mSelectedPosition;

    public CRMOrderAdapter(Context context) {
        this.mContext = context;
        mInflater = LayoutInflater.from(context);
    }

    public void bindData( ArrayList<CRMOrderByData> datas) {
        mOrderDatas = datas;
        notifyDataSetChanged();
    }

    public void setSelectedPosition(int position) {
        mSelectedPosition = position;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return mOrderDatas == null ? 0 : mOrderDatas.size();
    }

    @Override
    public CRMOrderByData getItem(int position) {
        return mOrderDatas == null ? null : mOrderDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        CRMOrderByData data = mOrderDatas.get(position);
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_crm_order_by, parent, false);
            viewHolder.text = (TextView) convertView.findViewById(R.id.tv_item_crm_order_by);
            viewHolder.image = (ImageView) convertView.findViewById(R.id.iv_item_crm_order_by);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.text.setText(data.getName());
        if (position == mSelectedPosition) {
            viewHolder.image.setVisibility(View.VISIBLE);
            viewHolder.text.setTextColor(mContext.getResources().getColor(R.color.crm_select_tab_blue_text));
        } else {
            viewHolder.image.setVisibility(View.GONE);
            viewHolder.text.setTextColor(mContext.getResources().getColor(R.color.schedule_content));


        }

        return convertView;
    }

    class ViewHolder {
        private TextView text;
        private ImageView image;
    }
}
